import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/ServletContextDemo")
public class ServletContextDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = getServletContext();
        //名称获取参数
        String nameValue = context.getInitParameter("username");
        System.out.println(nameValue);

        //获取访问虚拟路径
        String path = context.getContextPath();
        System.out.println(path);

        //虚拟目录获取磁盘绝对路径
        String a = context.getRealPath("/src/a.txt");
        System.out.println(a);

        String b = context.getRealPath("/WEV-INF/b.txt");
        System.out.println(b);

        String c = context.getRealPath("/c.txt");
        System.out.println(c);

        //设置共享数据
        context.setAttribute("name","lumingfei");
        //删除共享数据
        context.removeAttribute("name");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
